import 'package:flutter/cupertino.dart';
import 'package:frontend/reqs/requests.dart';

import '../models/global.dart';
import '../models/itemInfo.dart';

@Deprecated("购物车应该在后端实现")
class CartState extends ChangeNotifier {
  List<ItemInfo> items = Global.cart;

  CartState();

  addItem(ItemInfo item) {
    items.add(item);
    addToCart(Global.profile.user!.id, item.id);
    notifyListeners();
  }

  delItem(int itemId) {
    items.removeWhere((element) => element.id == itemId);
    delFromCart(Global.profile.user!.id, itemId);
    notifyListeners();
  }

  clearItem() {
    items.clear();
    clearCart(Global.profile.user!.id);
    notifyListeners();
  }

  submitOrders() {
    items.clear();
    checkOutAllInCart(Global.profile.user!.id, 0);
    notifyListeners();
  }
}
